home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2930 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.1 KB  |  113 lines

  1. Path: news.pi.net!news
  2. From: janc@pop.pi.net (Jan Cornelis)
  3. Newsgroups: comp.lang.c++
  4. Subject: Trees !, Who can help me to improve my trees code ! <janc@pi.net>
  5. Date: Sun, 21 Jan 1996 02:23:26 GMT
  6. Organization: Planet Internet
  7. Message-ID: <4dr86i$75f@neptunus.pi.net>
  8. NNTP-Posting-Host: asd18.pi.net
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Who can help me with the following code written. The code doesn't work
  12. properly. I cannot understand why it doesn't work and how it should be
  13. improved. Is somebody there capable to help me out correcting this
  14. code ?
  15. Then i would like you to ask to help me either with a function in
  16. searching through the tree !
  17.  
  18. My e-mail adress:  janc@pi.net
  19.  
  20. #include<stdio.h>
  21. class jc
  22. {
  23.     public:
  24.     jc()
  25.     {
  26.        tail=NULL;
  27.        count = 0;
  28.     }
  29.  
  30.    // This function should add a value to the tree ! 
  31.    void addtree(int p);
  32.  
  33.    // This function should print one value from the tree one by one !
  34.    void onefurther();
  35.  
  36.    private:
  37.    struct list
  38.    {
  39.    //  'e' is the integer number for the tree !
  40.      int e;
  41.    //  The left side of the tree
  42.      list *left;
  43.    //  The right side of the tree
  44.      list *right;
  45.    };
  46.  
  47.    int count;
  48.    list *tail;
  49. };
  50.  
  51. void jc::addtree(int p)
  52. {
  53.     if (tel==0)
  54.    {
  55.      tail = new list;
  56.      tail->links=NULL;
  57.      tail->rechts=NULL;
  58.      tait=NULL;
  59.      tail->e=p;
  60.      tel++;
  61.    }
  62.    else
  63.    {
  64.       if (p < tail->e)
  65.       {
  66.         if (tail->left!=NULL)
  67.         {
  68.            tail->left = new list;
  69.            tail = tail->left;
  70.         }
  71.         else
  72.         {
  73.              tail = tail-> right;
  74.         }
  75.       }
  76.       else
  77.       {
  78.         if (tail->right != NULL)
  79.         {
  80.            tail->right = new list;
  81.            tail = tail->right;
  82.         }
  83.         else
  84.         {
  85.           tail = tail->right;
  86.         }
  87.       }
  88.    tail->left = NULL;
  89.    tail->right = NULL;
  90.    tail->e=p;
  91.    }
  92. }
  93.  
  94. void jc::onefurther()
  95. {
  96.    tail = tail->left;
  97.    printf("\nThe value  = %i",tail->e);
  98.    tail = tail->right;
  99. }
  100.  
  101. void main()
  102. {
  103.    jc a;
  104.    
  105.    for (int i=1;i <= 6;i++)   
  106.    a.addtail(i);
  107.  
  108.    for (int k=1;k <= 6;k++)   
  109.    a.onefurther();    
  110. }
  111.  
  112.  
  113.